﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace AngelSpellMaker
{
    public partial class FormulaCalculator : Form
    {
        public FormulaCalculator()
        {
            InitializeComponent();
        }

        private void SelectFormulaType_SelectedIndexChanged(object sender, EventArgs e)
        {
            string abc = SelectFormulaType.Text;
            switch (abc)
            {
                case "COMBAT_FORMULA_LEVELMAGIC":
                    TextBoxML.Visible = true;
                    TextBoxMinA.Visible = true;
                    TextBoxMinB.Visible = true;
                    TextBoxLVL.Visible = true;
                    TextBoxMaxA.Visible = true;
                    TextBoxMaxB.Visible = true;
                    TextMagicLevel.Visible = true;
                    TextMinA.Visible = true;
                    TextMinB.Visible = true;
                    TextMaxA.Visible = true;
                    TextMaxB.Visible = true;
                    TextLVL.Visible = true;
                break;
            }
        }

        private void getAttackButton_Click(object sender, EventArgs e)
        {          
            // Formula type --> MagicLevel
            if (SelectFormulaType.Text == "COMBAT_FORMULA_LEVELMAGIC")
            {

                if (TextBoxML.Text == "" && TextBoxLVL.Text == "" && TextBoxMinA.Text == "" && TextBoxMinB.Text == "" && TextBoxMaxA.Text == "" && TextBoxMaxB.Text == "")
                {
                    MessageBox.Show("Complete all the fields to get the spell attack", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else if (TextBoxML.TextLength != 0 && TextBoxLVL.TextLength != 0 && TextBoxMinA.TextLength != 0 && TextBoxMinB.TextLength != 0 && TextBoxMaxA.TextLength != 0 && TextBoxMaxB.TextLength != 0)
                {
                    // Variables para La Formula
                    int ml = Convert.ToInt32(TextBoxML.Text);
                    int lvl = Convert.ToInt32(TextBoxLVL.Text);
                    int MinA = Convert.ToInt32(TextBoxMinA.Text);
                    int MinB = Convert.ToInt32(TextBoxMinB.Text);
                    int MaxA = Convert.ToInt32(TextBoxMaxA.Text);
                    int MaxB = Convert.ToInt32(TextBoxMaxB.Text);

                    // Funcion de Resultado de Ataque
                    string varchar = Convert.ToString(ResultFormula(ml, lvl, MinA, MinB, MaxA, MaxB));
                    string stringformula = "setCombatFormula(combat1, COMBAT_FORMULA_LEVELMAGIC, -" + MinA + ", -" + MinB + ", -" + MaxA + ", -" + MaxB + ")";
                    TextBoxResult.Clear();
                    TextBoxResult.AppendText(varchar);
                    FormulaStringBox.AppendText(stringformula);
                    InfoToolTip.SetToolTip(TextBoxResult, "The Attack of the spell is: " + varchar + "");
                }
                else
                {
                    MessageBox.Show("Complete all the fields to get the spell attack", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                MessageBox.Show("Select Formula type for Damage Calculator", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        // Method Result Formula
        public int ResultFormula(int magiclevel, int level, int mina, int minb, int maxa, int maxb)
        {
            int var1 = magiclevel * mina;
            int var2 = maxa * level;
            int var3 = minb + maxb;
            int var4 = var1 + var2;
            int var5 = var3 + var4;

            int result = var5 / 2;

            return result;
        }

        // Eventos de los TextBox para Solo Permitir Numeros
        #region Events TextBox Numeric
        private void NumericTextBoxML(object sender, KeyPressEventArgs e)
        {
            if (char.IsDigit(e.KeyChar) == true)
            { }

            //Codigo Ascii para el punto

            else if (e.KeyChar == 46)

            { }

            //codigo Ascii para la coma

            else if (e.KeyChar == 44)

            { }

            //Codigo Ascii para el Backspace

            else if (e.KeyChar == '\b')

            { }

            else

            { e.Handled = true; }

        }

        private void NumericLVL(object sender, KeyPressEventArgs e)
        {
            if (char.IsDigit(e.KeyChar) == true)
            { }

            //Codigo Ascii para el punto

            else if (e.KeyChar == 46)

            { }

            //codigo Ascii para la coma

            else if (e.KeyChar == 44)

            { }

            //Codigo Ascii para el Backspace

            else if (e.KeyChar == '\b')

            { }

            else

            { e.Handled = true; }
        }

        private void NumericMinA(object sender, KeyPressEventArgs e)
        {
            if (char.IsDigit(e.KeyChar) == true)
            { }

            //Codigo Ascii para el punto

            else if (e.KeyChar == 46)

            { }

            //codigo Ascii para la coma

            else if (e.KeyChar == 44)

            { }

            //Codigo Ascii para el Backspace

            else if (e.KeyChar == '\b')

            { }

            else

            { e.Handled = true; }
        }

        private void NumericMinB(object sender, KeyPressEventArgs e)
        {
            if (char.IsDigit(e.KeyChar) == true)
            { }

            //Codigo Ascii para el punto

            else if (e.KeyChar == 46)

            { }

            //codigo Ascii para la coma

            else if (e.KeyChar == 44)

            { }

            //Codigo Ascii para el Backspace

            else if (e.KeyChar == '\b')

            { }

            else

            { e.Handled = true; }
        }

        private void NumericMaxA(object sender, KeyPressEventArgs e)
        {
            if (char.IsDigit(e.KeyChar) == true)
            { }

            //Codigo Ascii para el punto

            else if (e.KeyChar == 46)

            { }

            //codigo Ascii para la coma

            else if (e.KeyChar == 44)

            { }

            //Codigo Ascii para el Backspace

            else if (e.KeyChar == '\b')

            { }

            else

            { e.Handled = true; }
        }

        private void NumericMaxB(object sender, KeyPressEventArgs e)
        {
            if (char.IsDigit(e.KeyChar) == true)
            { }

            //Codigo Ascii para el punto

            else if (e.KeyChar == 46)

            { }

            //codigo Ascii para la coma

            else if (e.KeyChar == 44)

            { }

            //Codigo Ascii para el Backspace

            else if (e.KeyChar == '\b')

            { }

            else

            { e.Handled = true; }
        }

#endregion        
    }
}
